<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算器</title>
</head>
<body>
<input type="text" id="i1">
<input type="text" id="i2">
<input type="button" value="加" onclick="f1('+')">
<input type="button" value="减" onclick="f1('-')">
<input type="button" value="乘" onclick="f1('*')">
<input type="button" value="除" onclick="f1('/')">
<div>
    结果:<span></span>
</div>


<script>
    function f1(key) {
        let a = document.querySelector("#i1");
        let b = document.querySelector("#i2");
        let c = document.querySelector("span");
        if(isNaN(a.value) || isNaN(b.value)) {
            c.innerText = "输入错误！";
            return;
        }
        switch (key) {
            case "+":
                c.innerText = a.value * 1 + b.value * 1;
                break;
            case "-":
                c.innerText = a.value - b.value;
                break;
            case "*":
                c.innerText = a.value * b.value;
                break;
            case "/":
                c.innerText = a.value / b.value;
                break;
        }

    }


</script>

</body>
</html>